home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / libg_261.zip / libg_261 / libg++ / README.SHLIB < prev    next >
Text File  |  1994-10-20  |  10KB  |  341 lines

  1. NOTES ON BUILDING LIBG++ AS A SUNOS4 SHARED LIBRARY
  2.  
  3. A shared library version of libg++-2.6.1 can be built using gcc-2.6.0 on a 
  4. SPARC10 running OS4.1.3. In order to get SUN shared libraries to work 
  5. properly with g++ it was necessary to patch collect2 [ld].  A hack of an 
  6. earlier version of collect2 done by Eric Schenk [schenk@cs.toronto.edu] was 
  7. massaged to work with gcc-2.6.0.  A context diff is included below.
  8.  
  9. To build a shared version of libg++ on a SPARC running OS4.1.3 
  10. do the following:
  11.  
  12. (0) patch collect2.c in gcc-2.6.1 and rebuild
  13. (1) patch libg++-2.6.1
  14. (2) start with a *clean* libg++-2.6.1 tree [make distclean] 
  15. (3) configure
  16. (4) edit the top-level Makefile:
  17.  
  18.     CC = gcc
  19.     CFLAGS = -g -O2 -fpic
  20.     CXXFLAGS = -g -O2 -fpic -fno-implicit-templates
  21.  
  22. (5) run make
  23. (6) build the shared lib from the PIC code
  24.     (a) cd libg++-2.6.1/libg++
  25.     (b) mkdir shared
  26.     (c) cd shared
  27.     (d) ar xv ../libg++.a
  28.     (e) mkdir unshared
  29.     (f) mv CursesW.o  ./unshared
  30.     (g) ld -o ../libg++.so.2.61 *.o -assert pure-text
  31.     (h) cd ./unshared
  32.     (i) ar rcv ../../libg++.sa.2.61 *.o
  33.     (j) ranlib ../../libg++.sa.2.61
  34.  
  35.  
  36. Discussion:
  37. ----------
  38.  
  39. The SUN link editor has an idiosyncracy [bug ???] which requires anything
  40. that is declared in a shared library to be defined even if it isn't used.
  41. CursesW.o declares functions that are defined in libcurses and libtermcap. 
  42. If CursesW.o had been incorporated into the ".so" piece, these two 
  43. libraries would  have to be added to the link statement even when the 
  44. CursesWindow class is not being used.  This situation was alleviated by 
  45. placing CursesW.0 into the ".sa" piece.
  46.  
  47. In addition, libg++.so.2.61 contains a number of classes which use the math
  48. library.  Consequently, the math library must to added to the link command
  49. even if these classes are not used.  There are far too many of these classes
  50. that declare math functions so it is just easier to add "-lm" to the link
  51. command.  One might consider splitting libg++ into two libraries: one that
  52. contains the contributions from libio and libiberty and another that contains
  53. Doug Lea's classes.  I've done some experimenting in this direction and have
  54. seen that such an approach is certainly viable.
  55.  
  56.  
  57. -----------------------collect2.c patch---------------------------------------
  58. *** collect2.c.orig    Mon Jul 11 15:08:16 1994
  59. --- collect2.c    Sun Jul 31 09:38:09 1994
  60. ***************
  61. *** 24,29 ****
  62. --- 24,34 ----
  63.   the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  64.   
  65.   
  66. + #ifdef sparc
  67. + #define SUNOS_SHARED_LIBS /* This should really be defined in a config file */
  68. + #endif
  69.   /* Build tables of static constructors and destructors and run ld. */
  70.   
  71.   #include <sys/types.h>
  72. ***************
  73. *** 223,231 ****
  74. --- 228,243 ----
  75.   static struct head constructors;    /* list of constructors found */
  76.   static struct head destructors;        /* list of destructors found */
  77.   
  78. + #ifdef SUNOS_SHARED_LIBS
  79. + static struct head shared_libs;     /* list of shared libraries to scan */
  80. + #endif
  81.   extern char *getenv ();
  82.   extern char *mktemp ();
  83.   extern FILE *fdopen ();
  84. + #ifdef SUNOS_SHARED_LIBS
  85. + static void  exec_ldd ();
  86. + #endif
  87.   
  88.   /* Structure to hold all the directories in which to search for files to
  89.      execute.  */
  90. ***************
  91. *** 1181,1186 ****
  92. --- 1193,1211 ----
  93.   
  94.     scan_prog_file (output_file, PASS_FIRST);
  95.   
  96. + #ifdef SUNOS_SHARED_LIBS
  97. +   /* Call ldd to determine dynamic depenencies, */
  98. +   /* and scan all .so files as well. */
  99. +   exec_ldd(output_file);
  100. +   {
  101. +     struct id *lib = shared_libs.first;
  102. +     while (lib) {
  103. +       scan_prog_file (lib->name, PASS_FIRST);
  104. +       lib = lib->next;
  105. +     }
  106. +   }
  107. + #endif
  108.     if (debug)
  109.       {
  110.         fprintf (stderr, "%d constructor(s) found\n", constructors.number);
  111. ***************
  112. *** 1328,1333 ****
  113. --- 1353,1470 ----
  114.   
  115.     do_wait (prog);
  116.   }
  117. + #ifdef SUNOS_SHARED_LIBS
  118. + static void
  119. + exec_ldd (outfile)
  120. +      char *outfile;
  121. + {
  122. +   void (*int_handler) ();
  123. +   void (*quit_handler) ();
  124. +   char *ldd_argv[3];
  125. +   int pid;
  126. +   int argc = 0;
  127. +   int pipe_fd[2];
  128. +   char *p, buf[1024];
  129. +   FILE *inf;
  130. +   ldd_argv[argc++] = "ldd";
  131. +   ldd_argv[argc++] = outfile;
  132. +   ldd_argv[argc++] = (char *)0;
  133. +   if (pipe (pipe_fd) < 0)
  134. +     fatal_perror ("pipe");
  135. +   inf = fdopen (pipe_fd[0], "r");
  136. +   if (inf == (FILE *)0)
  137. +     fatal_perror ("fdopen");
  138. +   /* Trace if needed.  */
  139. +   if (vflag || debug)
  140. +     {
  141. +       char **p_argv;
  142. +       char *str;
  143. +       fprintf (stderr, "%s", "/bin/ldd");
  144. +       for (p_argv = &ldd_argv[1]; (str = *p_argv) != (char *)0; p_argv++)
  145. +       fprintf (stderr, " %s", str);
  146. +       fprintf (stderr, "\n");
  147. +     }
  148. +   fflush (stdout);
  149. +   fflush (stderr);
  150. +   /* Spawn child ld on pipe */
  151. +   pid = vfork ();
  152. +   if (pid == -1)
  153. +     fatal_perror ("vfork");
  154. +   if (pid == 0)                       /* child context */
  155. +     {
  156. +       /* setup stdout */
  157. +       if (dup2 (pipe_fd[1], 1) < 0)
  158. +         fatal_perror ("Dup2 (%d, 1)", pipe_fd[1]);
  159. +       if (close (pipe_fd[0]) < 0)
  160. +         fatal_perror ("Close (%d)", pipe_fd[0]);
  161. +       if (close (pipe_fd[1]) < 0)
  162. +         fatal_perror ("Close (%d)", pipe_fd[1]);
  163. +       execv ("/bin/ldd", ldd_argv);
  164. +       fatal_perror ("Execute %s", "/bin/ldd");
  165. +     }
  166. +   /* Parent context from here on.  */
  167. +   int_handler  = (void (*) ())signal (SIGINT,  SIG_IGN);
  168. +   quit_handler = (void (*) ())signal (SIGQUIT, SIG_IGN);
  169. +   if (close (pipe_fd[1]) < 0)
  170. +     fatal_perror ("Close (%d)", pipe_fd[1]);
  171. +   if (debug)
  172. +     fprintf (stderr, "\nfind dependencies on shared libraries.\n");
  173. +   /* Read each line of ldd output.  */
  174. +   while (fgets (buf, sizeof buf, inf) != (char *)0)
  175. +     {
  176. +       int ch, ch2;
  177. +       char *start;
  178. +       char *end;
  179. +       /* Skip lines that complain about static linking */
  180. +       if (strstr(buf,"statically linked") != 0) continue;
  181. +       /* Find end of library name and null-terminate it.  */
  182. +       end = &buf[strlen(buf)-1];
  183. +       if (*end == '\n') (*end--) = 0;
  184. +       /* work backwards to find the start of the library name */
  185. +       start = end;
  186. +       while (!isspace(*start)) start--;
  187. +       start++;
  188. +       add_to_list (&shared_libs, start);
  189. +       if (debug)
  190. +         fprintf (stderr, "\t%s\n", buf);
  191. +     }
  192. +   if (debug)
  193. +     fprintf (stderr, "\n");
  194. +   if (fclose (inf) != 0)
  195. +     fatal_perror ("fclose of pipe");
  196. +   do_wait ("/bin/ldd");
  197. +   signal (SIGINT,  int_handler);
  198. +   signal (SIGQUIT, quit_handler);
  199. + }
  200. + #endif
  201.   
  202.   
  203.   /* Unlink a file unless we are debugging.  */
  204. -------------------------libg++-2.6.1 patches--------------------------------
  205. *** ./libg++/src/DLList.h.dist    Thu Oct 20 11:25:30 1994
  206. --- ./libg++/src/DLList.h    Thu Oct 20 14:24:13 1994
  207. ***************
  208. *** 52,58 ****
  209.       virtual void delete_node(BaseDLNode*node) = 0;
  210.       virtual BaseDLNode* copy_node(const void* datum) = 0;
  211.       virtual void copy_item(void *dst, void *src) = 0;
  212. !     virtual ~BaseDLList() { }
  213.   
  214.       Pix                   prepend(const void*);
  215.       Pix                   append(const void*);
  216. --- 52,59 ----
  217.       virtual void delete_node(BaseDLNode*node) = 0;
  218.       virtual BaseDLNode* copy_node(const void* datum) = 0;
  219.       virtual void copy_item(void *dst, void *src) = 0;
  220. !     virtual ~BaseDLList();
  221.   
  222.       Pix                   prepend(const void*);
  223.       Pix                   append(const void*);
  224. *** ./libg++/src/SLList.h.dist    Thu Oct 20 11:25:53 1994
  225. --- ./libg++/src/SLList.h    Thu Oct 20 14:26:54 1994
  226. ***************
  227. *** 49,55 ****
  228.       virtual void delete_node(BaseSLNode*node) = 0;
  229.       virtual BaseSLNode* copy_node(const void* datum) = 0;
  230.       virtual void copy_item(void *dst, void *src) = 0;
  231. !     virtual ~BaseSLList() { }
  232.       BaseSLList() { last = 0; }
  233.       void copy(const BaseSLList&);
  234.       BaseSLList& operator = (const BaseSLList& a);
  235. --- 49,55 ----
  236.       virtual void delete_node(BaseSLNode*node) = 0;
  237.       virtual BaseSLNode* copy_node(const void* datum) = 0;
  238.       virtual void copy_item(void *dst, void *src) = 0;
  239. !     virtual ~BaseSLList() ;
  240.       BaseSLList() { last = 0; }
  241.       void copy(const BaseSLList&);
  242.       BaseSLList& operator = (const BaseSLList& a);
  243. *** ./libg++/src/DLList.cc.dist    Thu Oct 20 14:24:27 1994
  244. --- ./libg++/src/DLList.cc    Thu Oct 20 14:25:59 1994
  245. ***************
  246. *** 25,30 ****
  247. --- 25,32 ----
  248.   #include <builtin.h>
  249.   #include "DLList.h"
  250.   
  251. + BaseDLList::~BaseDLList() {};
  252.   void BaseDLList::error(const char* msg) const
  253.   {
  254.     (*lib_error_handler)("DLList", msg);
  255. *** ./libg++/src/SLList.cc.dist    Thu Oct 20 14:26:28 1994
  256. --- ./libg++/src/SLList.cc    Thu Oct 20 14:27:26 1994
  257. ***************
  258. *** 25,30 ****
  259. --- 25,32 ----
  260.   #include <builtin.h>
  261.   #include "SLList.h"
  262.   
  263. + BaseSLList::~BaseSLList() {};
  264.   void BaseSLList::error(const char* msg) const
  265.   {
  266.     (*lib_error_handler)("SLList", msg);
  267. *** ./libio/procbuf.h.dist    Thu Oct 20 12:08:36 1994
  268. --- ./libio/procbuf.h    Thu Oct 20 12:09:31 1994
  269. ***************
  270. *** 30,36 ****
  271.       /* Following fields must match those in struct _IO_proc_file */
  272.       _IO_pid_t _pid;
  273.     public:
  274. !     procbuf() : filebuf() { }
  275.       procbuf(const char *command, int mode);
  276.       procbuf* open(const char *command, int mode);
  277.       procbuf *close() { return (procbuf*)filebuf::close(); }
  278. --- 30,36 ----
  279.       /* Following fields must match those in struct _IO_proc_file */
  280.       _IO_pid_t _pid;
  281.     public:
  282. !     procbuf();
  283.       procbuf(const char *command, int mode);
  284.       procbuf* open(const char *command, int mode);
  285.       procbuf *close() { return (procbuf*)filebuf::close(); }
  286. *** ./libio/procbuf.cc.dist    Thu Oct 20 12:09:05 1994
  287. --- ./libio/procbuf.cc    Thu Oct 20 12:10:10 1994
  288. ***************
  289. *** 28,33 ****
  290. --- 28,35 ----
  291.   #include "libioP.h"
  292.   #include "procbuf.h"
  293.   
  294. + procbuf::procbuf() : filebuf() {}
  295.   procbuf::procbuf(const char *command, int mode) : filebuf()
  296.   {
  297.     _IO_proc_open(this, command, (mode & ios::in) ? "r" : "w");
  298.  
  299.  
  300. -- 
  301. Dr. Joseph E. Sacco            | Internet: jsacco@ssl.com
  302. Sacco Scientific               | 
  303. 6 Buena Vista Street           | FAX:      (617)233-3611
  304. Saugus, MA 01906-2606          | Voice:    (617)233-4212
  305.